import Cookies from 'js-cookie'

const state = {
  sidebar: {
    opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : false
  }
}

const mutations = {
  TOGGLE_SIDEBAR: (state, isCollapse) => {
    if (isCollapse) {
      state.sidebar.opened = true
      Cookies.set('sidebarStatus', 1)
    } else {
      state.sidebar.opened = false
      Cookies.set('sidebarStatus', 0)
    }
  }
}

const actions = {
  toggleSideBar({ commit }, isCollapse) {
    commit('TOGGLE_SIDEBAR', isCollapse)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
